/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package studenttrack.entity;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Temporal;
import java.util.ArrayList;
import javax.persistence.Table;
import stException.SubmissionAlreadyMadeException;
import stException.SubmissionNotMadeForThisAssessmentException;

/**
 *
 * @author tg227
 */
@Entity
public class Assessment implements AssessmentInterface {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    public Long getSequenceNumber() {
        return id;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Assessment)) {
            return false;
        }
        Assessment other = (Assessment) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "studenttrack.entity.Assessment[id=" + id + "]";
    }

    //end gen code

    private String moduleID;
    private String type; // change to enum? not sure if enums can be passed in EJB
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date handOut;
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date handIn;
    private int duration;
    private int weighting;
    private int averageMark;
    private ArrayList<Long> submissions;

    public int getDuration() {
        return duration;
    }

    public void setDuration(int duration) {
        this.duration = duration;
    }

    public Date getHandIn() {
        return handIn;
    }

    public void setHandIn(Date handIn) {
        this.handIn = handIn;
    }

    public Date getHandOut() {
        return handOut;
    }

    public void setHandOut(Date handOut) {
        this.handOut = handOut;
    }

    public String getModuleID() {
        return moduleID;
    }

    public void setModuleID(String moduleID) {
        this.moduleID = moduleID;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public int getWeighting() {
        return weighting;
    }

    public void setWeighting(int weighting) {
        this.weighting = weighting;
    }

    public long[] getSubmissions() {
        long[] su = new long[submissions.size()];
        int i = 0;
        while(i < su.length){
            su[i] = submissions.get(i);
            i++;
        }
        return su;
    }

    public void addSubmission(long submissionID) throws SubmissionAlreadyMadeException {
        if(submissions.contains(submissionID)){
            throw new SubmissionAlreadyMadeException();
        } else {
            submissions.add(submissionID);
        }
    }
    
    public void removeSubmission(long submissionID) throws SubmissionNotMadeForThisAssessmentException {
        if(submissions.contains(submissionID)){
            submissions.remove(submissionID);
        } else {
            throw new SubmissionNotMadeForThisAssessmentException();
        }
    }



}
